home *** CD-ROM | disk | FTP | other *** search
- /*
- GetClicks.c
- waits for a mouse click, and then counts clicks (e.g. double-click, triple-click). Each
- click must arrive within the acceptable double-click time of the previous,
- as set in the Control Panel. Returns the number of clicks, 1 or more.
- HISTORY:
- 4/30/88 dgp wrote it
- 3/31/90 dgp cleaned up code and documentation.
- 8/24/91 dgp Made compatible with THINK C 5.0.
- 3/30/91 dgp use SndStop1() instead of obsolete Sound Driver.
- 1/25/93 dgp removed obsolete support for THINK C 4.
- 4/29/95 dgp added GetNextEventOrQuit(), so that we can abort at any time by hitting Command-.
- 6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
- */
- #include "VideoToolbox.h"
- short GetNextEventOrQuit(int mask,EventRecord *eventPtr);
-
- short GetClicks(void)
- {
- long ticks;
- EventRecord event;
- short clicks;
-
- clicks=0;
- while(!GetNextEventOrQuit(mDownMask,&event)) ;
- SndStop1(); /* Stop sound on first click */
- clicks++;
- ticks=TickCount()+GetDblTime();
- while(!GetNextEventOrQuit(mUpMask,&event)) ;
- while(TickCount() < ticks) /* wait as long a possible for another click */
- if(GetNextEventOrQuit(mDownMask,&event)){
- clicks++;
- ticks=TickCount()+GetDblTime();
- while(!GetNextEventOrQuit(mUpMask,&event)) ;
- }
- return clicks;
- }
-
- short GetNextEventOrQuit(int mask,EventRecord *eventPtr)
- {
- if(GetNextEvent(mask|keyDownMask,eventPtr))switch(eventPtr->what){
- case keyDown:
- if((eventPtr->message&charCodeMask)=='.' && eventPtr->modifiers&cmdKey){
- printf("\n“Command-.” EXITING.\n");
- exit(1);
- }
- return (mask&keyDownMask)!=0;
- default:
- return 1;
- }else return 0;
- }
-